package com.situ.springboot.service.impl;

import com.situ.springboot.pojo.BanjiCountVO;
import com.situ.springboot.mapper.BanjiMapper;
import com.situ.springboot.pojo.Banji;
import com.situ.springboot.service.IBanjiService;
import com.situ.springboot.util.LayUITableResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BanjiServiceImpl implements IBanjiService {
    @Autowired
    private BanjiMapper banjiMapper;

    @Override
    public List<Banji> selectAll() {
        return banjiMapper.selectAll();
    }

    @Override
    public void deleteById(Integer id) {
        banjiMapper.deleteById(id);
    }

    // Service:业务
    @Override
    public LayUITableResult selectByPage(Integer page, Integer limit, Banji banji) {
        // 查询当前页的数据
        // select * from banji limit (page-1)*limit,limit
        int offset = (page - 1) * limit;
        List<Banji> list = banjiMapper.selectByPage(offset, limit, banji);

        // 查询总的数量
        long count = banjiMapper.selectTotalCount(banji);

        return LayUITableResult.ok(list, count);
    }

    @Override
    public void add(Banji banji) {
        banjiMapper.add(banji);
    }

    @Override
    public Banji selectById(Integer id) {
        return banjiMapper.selectById(id);
    }

    @Override
    public void update(Banji banji) {
        banjiMapper.update(banji);
    }

    @Override
    public void deleteAll(Integer[] ids) {
        // delete form banji where id in(10,16);
        for (Integer id : ids) {
            deleteById(id);
        }
    }

    @Override
    public List<BanjiCountVO> getBanjiCount() {
        return banjiMapper.getBanjiCount();
    }
}
